import { JSEncrypt } from 'jsencrypt'
/**
 * 加密
 * @param string 加密的内容
 * @returns 
 */
//'公钥'
let publicKey = `
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjiODqLtl+1a0hkAv/DoB5IQvauK1rP/Fe0JJCCbiZDU1W5m4uI2Ii5gOoPOSurT4pf/afKZt4LWU3xzQssvPXUpLl9FRgflOBVKDFdevARxzoViW2V4SSMfW6X3/GIKd0nJNSLgq4hFEaA/2vC6jBLwrtM2dgYFwAho4wUhDI2QIDAQAB
`
//'私钥'
let privateKey= `
:MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKOI4Oou2X7VrSGQC/8OgHkhC9q4rWs/8V7QkkIJuJkNTVbmbi4jYiLmA6g85K6tPil/9p8pm3gtZTfHNCyy89dSkuX0VGB+U4FUoMV168BHHOhWJbZXhJIx9bpff8Ygp3Sck1IuCriEURoD/a8LqMEvCu0zZ2BgXACGjjBSEMjZAgMBAAECgYANCbes1AlhFFYWS+646gYSIjFYwcqJt3Jd9dEDVNUT1ryoxfxYz1deoun9usUcrBE9q8cUz3NmtG/Sb55YRfgsvPcDXR4SqweLXSJqhOhgmID2c0/PMPasCObzoce08ty/AvrSIXVSWWKXgzZ+JcXWGi4KjVOUUzWdkHDU0T/ggQJBAM6WOMmbhU7AfKTGJI/PqnUxGCSpIpJ+i0SI+ORNlv69cv1c34LSw1zivn7sqCcGHNrIXqQsdGWHoQ8A42A5lxECQQDKpnpNruuxNIlIocMU57vSVbG0cCgjZSB5jUMvSS0YhZ8Olkbzj/ZkrZD7rwTSggRocGFquOfTV6Rmh/8WW2VJAkEAg9T9fDqQwYa4g/YmEtf08UBZJdwBQfcbLKs0GY0iFIIVRXXk9HlHTpkr85dWX0DZXQyMyLvNs5TvxMFOWHOn4QJAZMqwgfrCV3zd2zY5pSgtDsx4elpeXFxr7okIJXir6UpsdgDggTvVPPXm6od+SoVIU/mxOjeFdmRc7HIvuZrzoQJATdv3a0u3Z+zB7oHwpsM927pBG3KBNSVjnnrqx8b/fKwszh/qDUcXnEwCYFG631ySwJDVRYP3F7lMpEpSomgjaQ==
`
//加密
export function encryption (string) {
  const encrypt = new JSEncrypt()
  encrypt.setPublicKey(publicKey)
  const encrypted = encrypt.encrypt(string)
  return encrypted
}

// 解密（一般不在前端解密，都是后端进行解密）
export function decrypt (string ) {
  let decrypt = new JSEncrypt()
  decrypt.setPrivateKey(privateKey)
  var decryptMsg = decrypt.decrypt(string)
  return decryptMsg
}